<template>
	<view style="width: 80%;padding: 60% 0 0;margin: 0 auto;">
		<!-- #ifdef MP-WEIXIN || MP-BAIDU || MP-QQ -->
		<button type="primary" open-type="getUserInfo" @getuserinfo="mpGetUserInfo">获取用户信息</button>
		<!-- #endif -->
	</view>
</template>

<script>
	export default {
		data() {
			return {}
		},
		onLoad() {},
		computed: {},
		onShow() {},
		methods: {
			mpGetUserInfo(result) {
				if (result.detail.errMsg !== 'getUserInfo:ok') {
					uni.showModal({
						title: '获取用户信息失败',
						content: '错误原因' + result.detail.errMsg,
						showCancel: false
					});
					return;
				}
				this.fStoreUserInfo(result.detail.userInfo)
			},
			fStoreUserInfo(userInfo) {
				const _that = this
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						_that.$u.api.login(loginRes.code).then(res => {
							_that.$u.vuex('vuex_token', res.data)
							_that.$u.route({
								url: "pages/index",
								type: 'redirectTo'
							})
						})
					}
				});
			}
		}
	}
</script>

<style>
</style>
